home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 121_01 / ccc.c < prev    next >
Text File  |  1985-08-19  |  3KB  |  114 lines

  1. /*
  2. HEADER: CUG 121.??;
  3.  
  4.     TITLE:    ccc - a command driver for BDS C;
  5.     VERSION:    1.0;
  6.     DATE:    01/11/86;
  7.     DESCRIPTION: "Ccc is a command driver for BDS C.  It takes global flags,
  8.         and one or more sets of local flags plus filenames.
  9.         It builds a submit file to compile all the files with an
  10.         extension of .c, and link the output with the remaining
  11.         files, using the l2 linker.";
  12.     KEYWORDS:    command, driver;
  13.     SYSTEM:    CP/M;
  14.     FILENAME:    CCC.C;
  15.     WARNINGS:    "Copyright (c) 1981, Mike W. Meyer.
  16.         The link step uses the L2 linker; this has the problem that
  17.         you can't get to the L2 overlay stuff currently (the -m, -org,
  18.         -ovl flags are passed to the compiler).
  19.         By changing the appropriate #define, it is possible to use
  20.         CLINK instead; however, this will probably make things
  21.         worse, due to conflicts with the -o, -d, and -r flags.
  22.         One minor problem is that flags to the C compiler must not
  23.         have a space between themselves and their argument.";
  24.     AUTHORS:    Mike W. Meyer;
  25.     COMPILERS:    BDS-C 1.50;
  26. */
  27.  
  28. /*
  29.  *    Examples:
  30.  *        compile pencil & printer, externals at 6100, linking in others
  31.  *            'ccc -e6100 pencil.c printer.c driver -l crayon queue'
  32.  *
  33.  *        same thing, done wrong:
  34.  *            'ccc -e 6100 ' etc.
  35.  */
  36. #include <bdscio.h>
  37.  
  38. #define LINKER        "l2"
  39. #define COMPILER    "cc"
  40. #define SUBFILE        "cc.sub"
  41.  
  42. main(argc, argv) char **argv; {
  43.     char *tap, subfile[BUFSIZ], temp[MAXLINE], submit ;
  44.     char linkline[MAXLINE], comline[MAXLINE], comflags[MAXLINE] ;
  45.     int in, defdisk ;
  46.  
  47.     if (argc < 2 || argv[1][0] == '?') {
  48.         puts("usage: ccc [flags] file [flags] [file [flags]] [*]\n") ;
  49.         exit(0) ;
  50.         }
  51.     unlink(SUBFILE) ;            /* a safety measure */
  52.     if (fcreat(SUBFILE, subfile) == ERROR)
  53.         barf("Can't creat the submit file!\n") ;
  54.     defdisk = ERROR; submit = TRUE; *comline = *comflags = NULL ;
  55.     strcpy(linkline, LINKER) ;
  56.     while (tap = *++argv, --argc)
  57.         if (*tap == '-')
  58.             switch (tap[1]) {
  59.                 /* the compiler flags */
  60.                 case 'P': case 'A': case 'D': case 'M':
  61.                 case 'E': case 'O': case 'R': case 'S':
  62.                     strpad(*comline ? comline : comflags,
  63.                         tap) ;
  64.                     break ;
  65.                 /* the ccc flag */
  66.                 case 'N': submit = FALSE ;
  67.                       break ;
  68.                 /* the linker flags */
  69.                 default: strpad(linkline, tap) ;
  70.                 }
  71.         else {
  72.             if (defdisk == ERROR)
  73.                 defdisk = tap[1] == ':' ? *tap : FALSE ;
  74.             if (index(tap, ':') == ERROR && defdisk)
  75.                 sprintf(temp, "%c:%s",    defdisk, tap) ;
  76.             else
  77.                 strcpy(temp, tap) ;
  78.             if ((in = index(temp, '.')) != ERROR) {
  79.                 if (*comline)
  80.                     fprintf(subfile, "%s %s\n",
  81.                             comline, comflags) ;
  82.                 sprintf(comline, "%s %s", COMPILER, temp) ;
  83.                 temp[in] = NULL ;
  84.                 }
  85.             strpad(linkline, temp) ;
  86.             }
  87.     if (*comline) fprintf(subfile, "%s %s\n", comline, comflags) ;
  88.     fprintf(subfile, "%s\n", linkline) ;
  89.     if (submit) fprintf(subfile, "era %s\n%c", SUBFILE, CPMEOF) ;
  90.     else putc(CPMEOF, subfile) ;
  91.     fflush(subfile) ;
  92.     fclose(subfile) ;
  93.     if (submit && execl("SUBMIT", "CC", 0))
  94.         barf("Uh... Boss, I need a submit.\n") ;
  95.     else printf("Your submit file is named %s.\n", SUBFILE) ;
  96.     }
  97.  
  98. index(string, element) char *string, *element; {
  99.     char *other ;
  100.  
  101.     other = string ;
  102.     while (*other != element)
  103.         if (!*other++) return ERROR ;
  104.     return other - string ;
  105.     }
  106.  
  107. strpad(dest, source) char *dest, *source; {
  108.  
  109.     while (*dest++)
  110.         ;
  111.     dest[-1] = ' ' ;
  112.     strcpy(dest, source) ;
  113.     }
  114.